home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / Premiere 4.2 SDK r3 Mac / Examples / Projects / Additive Dissolve / Additive Dissolve.c < prev    next >
Text File  |  1996-01-25  |  4KB  |  130 lines

  1. //========================================================================================
  2. //
  3. // Additive Dissolve.c - Additive crossfade transition.
  4. //
  5. // Part of the Adobe Premiere¬ 4.2 Plug-In Developer's Toolkit.
  6. //
  7. // Written by Randy Ubillos and Bryan K. "Beaker" Ressler.
  8. //
  9. // Copyright ⌐ 1993-96, Adobe Systems Incorporated, all rights reserved worldwide.
  10. //
  11. // Version    1.00    10/20/93    Original version.
  12. // Version    1.01    9/12/94        Updated for 4.0.
  13. // Version  1.02    10/6/95     Updated for 4.2 and CW7.
  14. //
  15. //========================================================================================
  16.  
  17. //========================================================================================
  18. // Includes - use precompiled headers if compiling with CodeWarrior.
  19. //========================================================================================
  20. #ifdef __MWERKS__
  21.     #ifdef powerc
  22.         #include "PremierePPC"
  23.     #else
  24.         #include "Premiere68k"
  25.     #endif
  26. #else
  27.     #include "Premiere.h"
  28. #endif
  29.  
  30. //========================================================================================
  31. // Perform the transition
  32. //========================================================================================
  33. pascal short main (short selector, EffectHandle theData)
  34. {
  35.     short        result = 0;
  36.     long        spot;
  37.     Rect        box;
  38.     RGBColor    theColor, pin;
  39.     GWorldPtr    oldWorld;
  40.     GDHandle    oldDev;
  41.  
  42.     // Save the current GWorld/GDevice
  43.     GetGWorld(&oldWorld, &oldDev);
  44.  
  45.     // Act according to the selector
  46.     switch (selector) {
  47.         case esExecute:
  48.             // Preset pin color to pure white. Retrieve box for use in the CopyBits calls.
  49.             pin.red = pin.green = pin.blue = 0xFFFF;
  50.             box = ((GrafPtr)(*theData)->destination)->portRect;
  51.  
  52.             // calculate percentage of 131071
  53.             spot = (*theData)->part * (long)131071 / (*theData)->total;
  54.             
  55.             if (spot < 65536) {
  56.                 // We're in the first half of the transition (0% - 50%)
  57.  
  58.                 // Calculate the mixing value and set OpColor accordingly
  59.                 theColor.red = theColor.green = theColor.blue = spot;
  60.                 OpColor(&theColor);
  61.                 
  62.                 // Copy source 1 into the destination
  63.                 CopyBits((BitMap *)&(*theData)->source1->portPixMap,
  64.                     (BitMap *)&(*theData)->destination->portPixMap,
  65.                     &box, &box, srcCopy, nil);
  66.                 
  67.                 // Fill source 1 with black. We'll temporarily use source 1 to blend
  68.                 // source 2 with black.
  69.                 SetGWorld((*theData)->source1, nil);
  70.                 PaintRect(&box);
  71.                 SetGWorld(oldWorld, oldDev);
  72.                 
  73.                 // Blend source 2 with black (into source 1)
  74.                 CopyBits((BitMap *)&(*theData)->source2->portPixMap,
  75.                     (BitMap *)&(*theData)->source1->portPixMap, 
  76.                     &box, &box, blend, nil);
  77.                 
  78.                 // Reset the OpColor to white and addPin source 1 (which contains source 2
  79.                 // blended with black) into the destination (which contains source 1).
  80.                 OpColor(&pin);
  81.                 CopyBits((BitMap *)&(*theData)->source1->portPixMap,
  82.                     (BitMap *)&(*theData)->destination->portPixMap, 
  83.                     &box, &box, addPin, nil);
  84.  
  85.             } else {
  86.                 // We're in the second half of the transition (50% - 100%)
  87.  
  88.                 // Calculate the mixing value and set OpColor accordingly
  89.                 theColor.red = theColor.green = theColor.blue = 131072 - spot;
  90.                 OpColor(&theColor);
  91.                 
  92.                 // Copy source 2 into the destination
  93.                 CopyBits((BitMap *)&(*theData)->source2->portPixMap,
  94.                     (BitMap *)&(*theData)->destination->portPixMap, 
  95.                     &box, &box, srcCopy, nil);
  96.                 
  97.                 // Fill source 2 with black. We'll temporarily use source 2 to blend
  98.                 // source 1 with black.
  99.                 SetGWorld((*theData)->source2, nil);
  100.                 PaintRect(&box);
  101.                 SetGWorld(oldWorld, oldDev);
  102.                 
  103.                 // Blend source 2 with black (into source 1)
  104.                 CopyBits((BitMap *)&(*theData)->source1->portPixMap,
  105.                     (BitMap *)&(*theData)->source2->portPixMap, 
  106.                     &box, &box, blend, nil);
  107.                 
  108.                 // Reset the OpColor to white and addPin source 2 (which contains source 1
  109.                 // blended with black) into the destination (which contains source 2).
  110.                 OpColor(&pin);
  111.                 CopyBits((BitMap *)&(*theData)->source2->portPixMap,
  112.                     (BitMap *)&(*theData)->destination->portPixMap, 
  113.                     &box, &box, addPin, nil);
  114.             }
  115.             break;
  116.         case esSetup:
  117.             break;
  118.     }
  119.     
  120.     // Leave destination set up nicely
  121.     SetGWorld((*theData)->destination, nil);
  122.     ForeColor(blackColor);
  123.     BackColor(whiteColor);
  124.  
  125.     // Reset the GWorld/GDevice
  126.     SetGWorld(oldWorld, oldDev);
  127.     
  128.     return(result);
  129. }
  130.